package com.server.controller;

import com.server.anno.Sensitivity;
import com.server.domain.Code;
import com.server.domain.Response;
import com.server.entity.DeviceInfo;
import com.server.service.DeviceInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 设备信息表(DeviceInfo)表控制层
 *
 * @author wzw
 * @since 2024-07-24 10:17:49
 */
@RestController
@RequestMapping("deviceInfo")
public class DeviceInfoController {
    @Resource
    DeviceInfoService deviceInfoService;

    // 查询全部
    @GetMapping("/showAll")
    public Response DeviceInfoByTime() {
        List<DeviceInfo> data = deviceInfoService.showAll();
        return new Response("获取传感器表成功！",data, Code.RESONSE_OK);
    }
    @GetMapping("/selectByFunctions")
    public Response DeviceInfoByTime(String functions) {
        List<DeviceInfo> data = deviceInfoService.selectByFunctions(functions);
        if(data != null){
            return new Response("获取传感器表成功！",data, Code.RESONSE_OK);
        }else{
            return new Response("获取传感器表失败！请输入正确功能",null, Code.BUSINESS_PARAM_ERR);
        }
    }
    @PostMapping("/saveOrUpdateDeviceInfo")
    @Sensitivity
    public Response addDeviceInfo(@RequestBody DeviceInfo deviceInfo) {
        boolean is_insert = deviceInfoService.saveOrUpdate(deviceInfo);
        return new Response("要插入数据:"+deviceInfo,is_insert, Code.RESONSE_OK);
    }
}
